package com.hadoopSpark.services.test;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.aliyun.configuration.ConfigurationTool;
import com.aliyun.util.String2JsonTool;
import com.certificate.tool.SetTrustStore;
import com.common.constant.Constant;

/*
 * function: 【停止其中的某一个服务】
 * 		停止其中某一个服务实例列表： 查看用户在容器集群中创建的所有服务实例列表
 * 就是说，比方一个应用里有N个服务，如MR服务，spark服务，hive服务，
 * 就是查看这些的
 */
public class StopService {
	public static void main(String[] args) {
		CloseableHttpClient httpClient = null;
		// get certificate address
		try {
			SSLConnectionSocketFactory sslsf = SetTrustStore.getSSLConnection();
			// httpclient链接
			httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
			//args[0] = hadoop8_master
			HttpGet httpGet = new HttpGet(
					ConfigurationTool.getProperties(Constant.ALIYUN_SERVICES_URL)+args[0]+"/stop");
			
			// 使用客户端向服务器发送数据
			HttpResponse httpResponse = httpClient.execute(httpGet);

			if (httpResponse.getStatusLine().getStatusCode() == 200) {
				//输出协议，响应码，结果
				System.out.println(httpResponse.getProtocolVersion() + " "
						+ httpResponse.getStatusLine().getStatusCode() + " "
						+ httpResponse.getStatusLine().getReasonPhrase());
				//无返回体
				System.out.println("OK:200");
			} else {
				
				//输出协议，响应码，结果
				System.out.println(httpResponse.getProtocolVersion() + " "
						+ httpResponse.getStatusLine().getStatusCode() + " "
						+ httpResponse.getStatusLine().getReasonPhrase());
				
				String bodyAsString = EntityUtils.toString(httpResponse
						.getEntity());
				
				String2JsonTool.printJson(bodyAsString);
				
				System.out.println("Something is wrong!!!");
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			try {
				httpClient.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
		
	
	
	
	
	
	
	
